<?php
#############################################################################
# Diverse history stored in local files, e.g. searches or pathes.           #
#                                                                           #
# Author: consros 2010                                                      #
#############################################################################

require_once "pageTools.inc";
require_once "tools.inc";
require_once "settings.inc";

displayHtmlHeader("NMT support for eTVnet");
?>
<style type="text/css">
    table.headfoot { width: <?php echo PAGE_WIDTH?>px; background-color: #4d6080; }
    table.contents { width: <?php echo PAGE_WIDTH?>px; }
    td.link        { width: <?php echo (PAGE_WIDTH/4)?>px; }
</style>
<?php

displayHtmlBody("DEFAULTREF");
displayTopNavigation();

# default history is history of searches
$headerName = LANG_SEARCHES_INFO;
$linkPrefix = 'index.php?search=';
$historyFile = "history/search.txt";
$colsAmount = 4;

# support of other history kinds
if (isset($_GET['subject']) && $_GET['subject'] != 'search') {
    $headerName = LANG_WATCHES_INFO;
    $linkPrefix = 'index.php?path=';
    $historyFile = "history/path.txt";
    $colsAmount = 2;
}

# clean the history if wished
if (isset($_GET['clean'])) {
    saveHistory($historyFile, array());
}

$history = loadHistory($historyFile);
$history = array_reverse($history);

# header
print "<table class=\"headfoot\"><tr><td align=\"center\">\n$headerName";
if (count($history) > 0) {
    print '&nbsp;(<a href="' . $_SERVER['PHP_SELF'] . '?subject=';
    print $_GET['subject'] . '&clean=yes">' . LANG_CLEAN . "</a>)";
}
print "</td></tr></table><br />\n";

# history
print "<table class=\"contents\"><tr>\n";
$i = 0;
foreach ($history as $name => $link) {
    if ($i++ == $colsAmount) {
        $i = 1;
        print "</tr><tr>\n";
    }
    $link = $linkPrefix . urlencode(chop($link));
    $link = "<a href=\"$link\">".checkLink($name).'</a>';
    print "<td class=\"link\">$link</td>\n";
}
print "</tr></table><br />\n";

displayHtmlEnd();
?>
